{{--继承模板--}}
@extends('admin.layouts.common')
@section('content')
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-bottom:none;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input class="layui-input" name="key" id="key" placeholder="请输入查询内容">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btns-blacks" id="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button class="layui-btn layui-btn-blue onmousemovebtns" tipsmsg="添加用户组" onclick="x_admin_show('添加用户组','{{url('admin/auth/groupadd')}}','400px','220px','95%','45%')">
                        <i class="layui-icon layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body" style="margin-top: -20px;">
            <table id="list" lay-filter="list"></table>
        </div>
    </div>
    <script type="text/html" id="addtime">
        @{{layui.util.toDateString(d.addtime*1000,'yyyy-MM-dd HH:mm:ss')}}
    </script>
    <script type="text/html" id="action">
        <span>
            <button tipsmsg="编辑" class="layui-btn layui-btns-blue layui-btn-xs layuimsg" onclick="x_admin_show('编辑用户组','{{ url('admin/auth/groupedit') }}?id=@{{d.group_id}}','360px','220px','95%','45%')">
                <i class="iconfont icon-bianji2"></i>
            </button>
        </span>
        <span>
        <button tipsmsg="配置权限" class="layui-btn layui-btns-black layui-btn-xs layuimsg" onclick="x_admin_show('配置权限','{{ url('admin/auth/groupaccess') }}?id=@{{d.group_id}}','','','95%','95%')">
            <i class="iconfont icon-quanxian2"></i>
        </button>
    </span>
        <span>
            <button tipsmsg="删除" class="layui-btn layui-btns-red layui-btn-xs layuimsg"  lay-event="del">
                <i class="iconfont icon-shanchu-tianchong"></i>
            </button>
        </span>
    </script>
    <script src="{{asset('layuiadmin/layui/layui.js')}}"></script>
    <script src="{{asset('admin/js/jquery.2.1.1.min.js')}}"></script>
    <script src="{{asset('admin/js/common.js')}}"></script>
    <script>
        layui.use(['util'], function(){
            var util = layui.util;
            //固定块
            util.fixbar({
                bar1: '&#xe669'
                ,css: {right: 25, bottom: 25}
                ,bgcolor: '#393D39'
                ,click: function(type){
                    if(type === 'bar1'){
                        window.location.reload();
                    }else{

                    }
                }
            });
        });
    </script>
    <script>
        layui.use(['table','form','layer'], function() {
            var table = layui.table,form = layui.form,layer = layui.layer,$ = layui.jquery;
            var _token =  $('meta[name="csrf-token"]').attr('content');
            var tableIn = table.render({
                elem: '#list',
                url: "{{url('admin/auth/authgroup')}}",
                text:{none: '<i class="fa fa-snowflake-o" aria-hidden="true"></i>&nbsp;暂无相关数据'},
                method: 'post',
                even: true,
                where:{_token:_token},
                title: '管理员数据信息',
                page: true,
                cols: [[
                    {field: 'group_id', title: '编号',sort: true,width:150},
                    {field: 'title', title: '用户组名', edit: 'text'},
                    {field: 'addtime', title: '添加时间',width:180,sort: true, align: 'center',templet: "#addtime"},
                    {width: 140,title: '操作', align: 'center', toolbar: '#action',fixed: 'right'}
                ]],
                limits:[{{$infomsg['configinfo']['limit']}},100,200,400,600,1000,2000],
                limit:{{$infomsg['configinfo']['limit']}},//每页默认显示的数量
                done:function(){
                    onmousemoves();
                }
            });


            //搜索
            $('#search').on('click', function() {
                var key = $('#key').val();
                if($.trim(key)==='') {
                    layer.msg('请输入关键字！');
                    return;
                }
                tableIn.reload({
                    where: {key: key, _token:_token}
                })
            });

            //监听单元格编辑
            table.on('edit(list)', function(obj){
                var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
                var arrs ={
                    group_id:data.group_id,//验证的数据类类型
                    title:value,//提交的数据
                    _token:_token
                };
                $.post("{{url('admin/auth/groupedit')}}",arrs,function(res){
                    if(res.code===1){
                        layer.msg(res.msg);
                        tableIn.reload();
                    }else if(res.code===0){
                        layer.msg(res.msg);
                    }else{
                        layer.msg('你无操作权限!')  ;
                    }
                },'json')
            });

            table.on('tool(list)', function(obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('您确定要删除编号为： '+ data.group_id + ' 信息吗？', {icon: 3,skin: 'layui-layer-black',anim: 4,title:'删除'}, function(index){
                        $.post("{{url('admin/auth/groupdel')}}",{id:data.group_id, _token:_token},function(res){
                            if(res.code===1){
                                layer.msg(res.msg);
                                tableIn.reload();
                            }else if(res.code === 0) {
                                layer.msg(res.msg);
                            }else{
                                layer.msg('你无操作权限！');
                            }
                        },'json');
                        layer.close(index);
                    });
                }
            });

        });
    </script>
@endsection
